Skip to content

Fix frozenset() returning a frozenset subclass instance unchanged - #1350

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/frozenset-subclass-copy
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/frozenset-subclass-copy

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 5).

FrozenSetNode.frozensetIdentity returns the argument for any PFrozenSet when the class is the builtin one, including an instance of a subclass. CPython's make_new_frozenset returns the argument only when it is an exact frozenset.

AS-IS

>>> class F(frozenset): pass
...
>>> type(frozenset(F()))
<class '__main__.F'>

TO-BE

>>> type(frozenset(F()))
<class 'frozenset'>

(matching CPython)

Changes

  • Guard the identity specialization on an exact builtin frozenset argument; a subclass instance goes to the specialization that builds a new object over the same storage.
  • Add a test to tests/test_set.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_set.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_set (617 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

frozenset(x) returned x unchanged for any frozenset instance, including
an instance of a subclass. Only an exact frozenset is returned as is.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant